import { Body, Controller, Delete, Get, Inject, ParseBoolPipe, ParseIntPipe, Post, Query } from '@nestjs/common';
import { ApiQuery } from '@nestjs/swagger';
import { AppService } from './app.service';
import { VideoService } from './services/video.service';

@Controller()
export class AppController {
    constructor(
        @Inject(AppService)
        private readonly app: AppService,
        @Inject(VideoService)
        private readonly video: VideoService) {
    }

    @Get('/addBulk')
    @ApiQuery({name: 'dirpath', required: true})
    @ApiQuery({name: 'targetpath', required: true})
    @ApiQuery({name: 'all', required: false})
    addBulk(@Query('dirpath') dirpath: string,
            @Query('targetpath') targetpath: string,
            @Query('all', ParseBoolPipe) all: boolean) {
        return this.app.addBulk(dirpath, targetpath, all);
    }

    @Get('/list')
    listVideo(@Query('pageNum', ParseIntPipe) pageNum: number,
              @Query('pageSize', ParseIntPipe) pageSize: number) {
        return this.app.listVideo(pageNum, pageSize);
    }

    @Get('/file')
    @ApiQuery({name: 'id', required: false})
    @ApiQuery({name: 'md5', required: false})
    getFileInfo(@Query('id') id?: string,
                @Query('md5') md5?: string) {
        return this.app.getFileInfo(id, md5);
    }

    @Delete('/file')
    deleteFileInfo(@Query('md5') md5?: string) {
        return this.app.deleteFileInfo(md5);
    }

    @Post('/file')
    updateFileInfo(@Query('id') id: string, @Body() entity: any) {
        return this.app.updateFileInfo(id, entity);
    }

    @Get('/action')
    action(@Query('filepath') filepath: string,
           @Query('targetpath') targetpath: string) {
        return this.video.action(filepath, targetpath);
    }
}
